<template>
  <div class="p-4">
    <div class="flex justify-between items-center mb-4">
      <h1 class="text-2xl font-bold text-slate-800 ">编辑 RSS 源</h1>
    </div>
    <el-card shadow="never">
      <RssFeedForm :model-value="form" @submit="handleSubmit" @cancel="goList" />
    </el-card>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { ElMessage } from 'element-plus'
import { useRoute } from 'vue-router'
import { rssFeedAPI } from '@/services/api'
import RssFeedForm from '@/components/admin/fetch/rss/RssFeedForm.vue'

definePageMeta({ layout: 'admin' })

const route = useRoute()
const id = Number(route.params.id)
const form = ref({})

const goList = () => navigateTo('/admin/fetch/rss/list')

const loadDetail = async () => {
  const data = await rssFeedAPI.getById(id)
  form.value = data || {}
}

const handleSubmit = async (data) => {
  await rssFeedAPI.update(id, data)
  ElMessage.success('更新成功')
  goList()
}

onMounted(loadDetail)
</script>



